package com.netty.esc.controller;

import com.alibaba.fastjson.JSONObject;
import com.netty.esc.Interceptor.annotation.ControllerMapping;
import com.netty.esc.Interceptor.annotation.FuckAll;
import com.netty.esc.common.base.BaseResponseDTO;
import com.netty.esc.common.global.UserCache;
import com.netty.esc.entity.model.PersonTalkCountDTO;
import com.netty.esc.entity.model.PersonTalkDTO;
import com.netty.esc.entity.pojo.UserInfo;
import com.netty.esc.service.http.ConversationService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: ConversationCoontroller
 * @Description:
 * @Author: ZY
 * @Date: 2022/12/21 16:54
 * 对话层
 **/
@FuckAll
@ControllerMapping("/conversation")
public class ConversationCoontroller {

    @Resource
    ConversationService conversationService;

    /**
     * 查看未读历史记录
     */
    @GetMapping("/history/num")
    public BaseResponseDTO<?> findHistoryNum(){
        UserInfo currentUser = UserCache.getCurrentUser();
        List<PersonTalkCountDTO> historyNum = conversationService.findHistoryNum(currentUser);
        return BaseResponseDTO.setResultSuccess(historyNum);
    }

    /**
     * 查看历史记录
     */
    @GetMapping("/history")
    public BaseResponseDTO<?> findHistory(@RequestBody JSONObject jsonObject){
        Integer page = jsonObject.getInteger("page");
        Integer size = jsonObject.getInteger("size");
        Long sendId = jsonObject.getLong("sendId");
        List<PersonTalkDTO> history = conversationService.findHistory(page, size, sendId);
        return BaseResponseDTO.setResultSuccess(history);
    }
}
